<template>
	<view class="container">
		<u-navbar title="联系我们">
		</u-navbar>
		<view v-for="(item, index) in contacts" :key="index" class="list-item u-flex-xy-center">
			<!-- 联系人信息 -->
			<view class="item-content">
				<!-- 姓名和职位 -->
				<view class="name-position">
					<text class="name">{{ item.name }}</text>
					<text class="position">{{ item.position }}</text>
				</view>

				<!-- 部门和电话 -->
				<view class="department-phone" v-if="item.department">
					<text class="department">{{ item.department }}</text>
					<!-- <text class="phone">{{ item.phone }}</text> -->
				</view>
			</view>
			<view class="call u-flex-xy-center" @click="handleCall(item.phone)">
				<u-icon name="phone" color="#fff" size="24"></u-icon>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		getHomeInfo,
	} from "@/api/index.js";
	export default {
		data() {
			return {
				contacts: []
			};
		},
		mounted() {
			this.init()
		},
		methods: {
			async init() {
				let {
					data
				} = await getHomeInfo({
					code: "CONTACTUS",
				});
				this.contacts = JSON.parse(data.paramConf)
				// console.log(JSON.parse(data.paramConf), JSON.stringify(this.contacts));
			},
			handleCall(phoneNumber) {
				// 处理电话号码中的"转"字
				const cleanedNumber = phoneNumber;
				uni.makePhoneCall({
					phoneNumber: cleanedNumber,
					success: () => {
						console.log('拨号成功');
					},
					fail: (err) => {
						console.error('拨号失败:', err);
					}
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	/* 根容器 */
	.container {
		min-height: 100vh;
		background-color: #f5f5f5;
		padding-bottom: 40rpx;

		.call {
			width: 80rpx;
			height: 80rpx;
			background: #39C03E;
			border-radius: 50%;
		}
	}

	/* 列表容器 */
	.list-container {
		height: 100%;
		padding: 20rpx;
	}

	/* 列表项 */
	.list-item {
		background-color: white;
		border-radius: 10rpx;
		margin: 20rpx;
		padding: 30rpx;
	}

	/* 内容区域 */
	.item-content {
		flex: 1;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		height: 100%;
	}

	/* 姓名和职位 */
	.name-position {
		display: flex;
		flex-direction: column;
	}

	.name {
		font-size: 32rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.position {
		font-size: 28rpx;
		color: #666;
	}

	/* 部门和电话 */
	.department-phone {
		display: flex;
		flex-direction: column;
		margin-top: 20rpx;
	}

	.department {
		font-size: 28rpx;
		color: #666;
		margin-bottom: 10rpx;
	}

	.phone {
		font-size: 28rpx;
		color: #007AFF;
		font-weight: bold;
	}

	/* 分割线 */
	.divider {
		height: 2rpx;
		background-color: #eeeeee;
		margin-top: 20rpx;
	}
</style>